﻿using System.Linq;
using System.Web.Mvc;
using SC2ProArena.Domain.Model.Players;
using SC2ProArena.Domain.Model.Games;

namespace SC2ProArena.Interfaces.Controllers
{
	public class PlayersController : Controller
	{
		private IPlayerRepository _playerRepository;

		public PlayersController(IPlayerRepository playerRepository)
		{
			_playerRepository = playerRepository;
		}

		public ActionResult List(Race? race = null)
		{
			var query = new FindPlayersQuery();
			query.RaceFilter = race;
			var players = _playerRepository.FindBy(query);
			var playersToDisplay = players.Select(x => x.ToViewModel()).ToArray();
			return View(playersToDisplay);
		}
	}
}
